package org.vacoor.nothing.misc.express.usps.api.rate.v4;

import org.vacoor.nothing.misc.express.usps.api.UspsRequest;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

/**
 * USPS Domestic Rates API (V4) - request
 * USPS 国内费率请求
 *
 * @author vacoor
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "RateV4Request")
public class RateV4Request extends UspsRequest {
    // private String revision;    // optional, for full RateV4 functionality use Revision=“2”
    @XmlElement(name = "Package")
    private List<RatePackage> ratePackages;

    /* **********************
     *       Factory
     * **********************/

    public static RateV4Request create() {
        return new RateV4Request();
    }

    public static RateV4Request of(RatePackage... pkgs) {
        RateV4Request req = create();
        for (RatePackage pkg : pkgs) {
            req.add(pkg);
        }
        return req;
    }

    /* **********************
     *     Constructor
     * **********************/

    public RateV4Request() {
        this(null);
    }

    public RateV4Request(String revision) {
        super(revision);
    }

    /* *********************
     *        Methods
     * *********************/

    public List<RatePackage> getRatePackages() {
        return ratePackages;
    }

    public void setRatePackages(List<RatePackage> ratePackages) {
        this.ratePackages = ratePackages;
    }

    public RateV4Request add(RatePackage pkg) {
        if (null == ratePackages) {
            ratePackages = new ArrayList<RatePackage>();
        }
        ratePackages.add(pkg);

        return this;
    }
}
